﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Security;
using Marketplace.Engine.Model;
using Marketplace.Engine.Repository;
using Marketplace.Engine.Repository.Generic;

namespace Marketplace.Mvc.Controllers
{
    public class SellerController : Controller
    {
        //
        // GET: /Seller/

        public ActionResult Index()
        {
            IEnumerable<RentProperty> rentList = null;
            
            var membershipUser = Membership.GetUser();
            if (membershipUser != null)
            {
                var userId = membershipUser.ProviderUserKey.ToString();
            
                var repository = new RentPropertyRepository();
                var listResult = repository.GetList(new ListCondition<RentProperty>(p => p.OwnerId == (string) userId));

                rentList = listResult.Result;
            }
            else
            {
                rentList = new List<RentProperty>();
            }

            return View(rentList);
        }

        //
        // GET: /Seller/Details/5

        public ActionResult DetailRentProperty(int id)
        {
            return View();
        }

        public ActionResult DetailSaleProperty(int id)
        {
            return View();
        }

        //
        // GET: /Seller/Create

//        public ActionResult Create()
//        {
//            return View();
//        } 

        //
        // POST: /Seller/Create

//        [HttpPost]
//        public ActionResult Create(FormCollection collection)
//        {
//            try
//            {
                // TODO: Add insert logic here
//
//                return RedirectToAction("Index");
//            }
//            catch
//            {
//                return View();
//            }
//        }
        
        //
        // GET: /Seller/Edit/5
 
        public ActionResult EditRentProperty(int id)
        {
            var repository = new RentPropertyRepository();
            var rentProperty = repository.GetById(p => p.Id == id);
            
            return View(rentProperty);
        }

        //
        // POST: /Seller/Edit/5

        [HttpPost]
        public ActionResult EditRentProperty(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Seller/Edit/5

        public ActionResult EditSaleProperty(int id)
        {
            return View();
        }

        //
        // POST: /Seller/Edit/5

        [HttpPost]
        public ActionResult EditSaleProperty(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Seller/Delete/5
 
//        public ActionResult Delete(int id)
//        {
//            return View();
//        }

        //
        // POST: /Seller/Delete/5

//        [HttpPost]
//        public ActionResult Delete(int id, FormCollection collection)
//        {
//            try
//            {
                // TODO: Add delete logic here
// 
//                return RedirectToAction("Index");
//            }
//            catch
//            {
//                return View();
//            }
//        }
    }
}
